package D1123;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        Person p1=new Person("张飞","蜀国");
        Person p2=new Person("刘备","蜀国");
        Person p3=new Person("关羽","蜀国");
        Person p4=new Person("曹操","魏国");
        Person p5=new Person("孙权","吴国");
        List <Person>list=new  ArrayList();
        Collections.addAll(list,p1,p2,p3,p4,p5);
        //有条件删 改   非蜀国人删除
        for (Person p:list ){
            if (!p.getCountry().equals("蜀国")){
                list.remove(p);

            }
        }
        Iterator<Person> it=list.iterator();
        while(it.hasNext()){
            Person p=it.next();
            if(!p.getCountry().equals("蜀国")){
                it.remove();
            }
        }
        System.out.println(list.toString());

    }
}
